import { defineStore } from "pinia";
import { ref } from "vue";
import {getUserBaseInfo, getUserInfo} from '@/api/admin/user'
import { removeToken } from "@/composables/auth";


export const useUserStore = defineStore('user', () => {
    //用户信息
    const userInfo = ref({})

    //设置用户信息
    function setUserInfo() {
        getUserBaseInfo().then(res => {
            if (res.success == true) {
                userInfo.value = res.data
            }
        })
    }
    
    //退出登录
    function exitLogin() {
        //删除cookie中的jwt令牌
        removeToken()
        //删除用户登录信息
        userInfo.value = {}
    }

    return {userInfo, setUserInfo, exitLogin}
}, {persist: true}) //开启pinia持久化

